package com.sgb.knowledgeshare.viewmodel;

import androidx.lifecycle.ViewModel;

import com.sgb.knowledgeshare.ShareConfig;
import com.sgb.knowledgeshare.entity.ShareUserInfoEntity;
import com.sgb.knowledgeshare.view.fragment.ShareHomeFragment;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;
import java.util.HashMap;
import java.util.Map;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ShareHomeModel extends ViewModel {
    ShareHomeFragment sharehomefragment;

    public void setActivity(ShareHomeFragment shareHomeFragment) {
        sharehomefragment = shareHomeFragment;
    }

    //获取用户信息
    public void getUserHomePahe(String video_id) {
        Map map = new HashMap();
        map.put("userNo",video_id);
        ShareConfig.getInstance().getApi().getUserHomePage(map).enqueue(new ICallBack<BaseEntity<ShareUserInfoEntity>>() {
            @Override
            public void onSuccess(BaseEntity<ShareUserInfoEntity> data) {
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    sharehomefragment.setUserVideoListData(data.getData());
                }
            }
        });
    }

    //关注和取消关注
    public void getFens(String userNo) {
        Map map = new HashMap();
        map.put("userNo",userNo );
        ShareConfig.getInstance().getApi().getfens(map).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    sharehomefragment.UpdataUserIfno(userNo);
                } else {
                    MToast.showToast(sharehomefragment.getActivity(),data.getMsg());
                }
            }
        });
    }

}
